<template>
  <div>
    <van-nav-bar title="搜索" left-text="搜索" left-arrow @click-left="$router.go(-1)" />
    <div class="box1">
      <van-search v-model="inputval" show-action placeholder="请输入商品名称" @search="onSearch">
        <template #action>
          <div @click="onSearch">搜索</div>
        </template>
      </van-search>
    </div>
    <div class="box2">
      <h3>搜索历史</h3>
      <span v-for="(item, index) in oringein" :key="index" @click="fun(item)">
        {{
        item
        }}
      </span>
    </div>
    <div class="box3">
      <h3>畅销商品</h3>
      <span v-for="(item, index) in strum" :key="index">{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      inputval: " ",
      oringein: ["三文鱼", "凉皮", "包子"],
      strum: [
        "麻辣烫",
        "米线",
        "番茄意面",
        "蛋糕",
        "汉堡",
        "粥先生",
        "烤肉拌饭",
        "炸鸡"
      ]
    };
  },
  methods: {
    onSearch() {
      if (this.inputval != "") {
        this.oringein.push(this.inputval);
        this.oringein = Array.from(new Set(this.oringein));
        this.$router.push("/searchdetails/" + this.inputval);
      }
    },
    fun(item) {
      this.inputval = item;
    }
  }
};
</script>

<style lang="scss" scoped>
// .box2 {
//   padding: 10px;
//   box-sizing: border-box;
//   span {
//     display: inline-block;
//     padding: 4px 8px;
//     background-color: #eee;
//     margin-right: 8px;
//   }
// }
// .box3 {
//   padding: 0 10px;
//   box-sizing: border-box;
//   span {
//     display: inline-block;
//     padding: 4px 8px;
//     background-color: #eee;
//     margin: 0 10px 10px 0;
//   }
// }
</style>